package com.shigen.demo.controller;

import com.shigen.demo.entity.User;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class IndexController implements InitializingBean {

  @Value("${server.port}")
  private Integer port;

  @RequestMapping(value = "hello")
  public String hello() {
    return "hello " + port;
  }

  private Date date;

  @RequestMapping(value = "user")
  public Object argumentResolver(User user) {
    log.info("date: {}", date);
    return user;
  }

  /**
   * 此方法会在spring容器初始化之后调用
   */
  @Override
  public void afterPropertiesSet() {
    this.date = new Date();
  }
}
